<?php
/**
 * 系統名稱: Lotto 系統
 * 檔案說明: 專案管理-修改
 * $Author$
 * $Id$
 *
 */
include_once("../config.inc.php");
session_start();
$objMemberInfo = $_SESSION["Member_Info"];
if(time() - $objMemberInfo -> WagerCommonTime <= 1){
	sleep(1);
}
$objMemberInfo -> WagerCommonTime = time();

$_LangPath = "10m15_wager";	//語言檔參數，務必放在最前面

$intLID = (int)$_data["LottoID"];
$intGID = (int)$_data["GambleID"];
$intBT = (int)$_data["Bet_Type"];
$intNumber = (int)$_data["Number"];
if($intNumber != 1)$intNumber = 0;
$arrChoiceNumber = $_data["ChoiceNumber"];
//找出 Apoint
$intAN = (int)$_arrGLineNumToApointNum[$intLID][$intBT][$intNumber];

include_once(__Language_Path."/selectlanguage_member.php");
include_once(__Member_Path."/logincheck.php");
include_once(__Common_Path."/ExchangeRate.inc.php");
include_once(__Modules_Path."/joinnumber.lib.php");
include_once(__Modules_Path."/Wager.lib.php");
include_once(__Modules_Path."/WagerForm.lib.php");
include_once(__Common_Path."/Lotto.inc.php");
include_once(__Common_Path."/limit/LottoLimit_". $intLID. ".inc.php");
include_once(__Common_Path."/betparam/BetParam_". $intLID. ".inc.php");
include_once(__Root_Path."/tmp/credit-". $objMemberInfo -> ID .".php");
if(__isConnectToOtherWeb == 1){
	$flMemERate = (empty($objMemberInfo -> ExRate))?1:$objMemberInfo -> ExRate;
}else{
	$flMemERate = (empty($_ECRate[$objMemberInfo -> ERID]["Rate"]))?1:$_ECRate[$objMemberInfo -> ERID]["Rate"];
}

if($objMemberInfo -> isLock == '2'){
	$GLOBALS["errormessage"] = $_strStopWager;
	include("wager_error.php");
}

$intLType = (int)$_arrLotto[$intLID]["LType"];
$arrGroupCounter[1] = array(30 => 6, 31 => 5, 32 => 2, 33 => 3, 34 => 4, 35 => 2, 36 => 3, 37 => 4, 38 => 2, 39 => 3, 40 => 4, 41 => 2, 42 => 3, 43 => 4);
$arrGroupCounter[4] = array(15 => 1, 16 => 2, 17 => 3, 18 => 3, 19 => 4, 20 => 4, 21 => 5, 22 => 5, 23 => 5, 24 => 2, 25 => 2, 26 => 3, 27 => 4, 28 => 5, 30 => 2, 31 => 3, 32 => 4, 33 => 2, 34 => 3, 35 => 4);

if($intLType == 1 && $intBT == 30)$intNumber = 0;

$intGroupCounter = $arrGroupCounter[$intLType][$intBT];
if ($intGroupCounter == null || $intGroupCounter <= 0) {
	$Err_Message = $_str10M15Wager["Err_Message"];
	$Err_HiddenMessage = $_str10M15Wager["Err_Message"];
	include("wager_error.php");
}

//包車
$arrNum = array();
$arrOID = array();
if($intNumber == 0){
	//排序+做列表
	if (!is_array($arrChoiceNumber)) {
		$Err_Message = $_str10M15Wager["Err_Message"];
		$Err_HiddenMessage = $_str10M15Wager["Err_Message"];
		include("wager_error.php");
	}

	sort($arrChoiceNumber);
	$arrOrderList = array();
	foreach($arrChoiceNumber as $value) {
		$arrData = explode(":", $value);
		$intNum = (int)$arrData[0];	 //號碼
		$intOID = (int)$arrData[1];  //賠率序號
		$intChoiceCounter++;
		$strNum = sprintf("%02s", $intNum);

		$arrNum[$intNum] = $strNum;
		$arrOID[$intNum] = $intOID;
	}
	//下注號碼
	$strOrderStakeNumber = implode("|", $arrNum);

	//取得下注總組數
	$intChoiceGroup = count(combination($arrNum, $intGroupCounter));
	$strChoiceCounter = (int)$intChoiceCounter;
	$arrOrderList = $arrNum;

//排碰
}else{
	$arrCTNo = array();
	$arrChoiceTNo = array();
	$arrChoiceList = array();
	$arrOrderList = array();
	$arrChoiceCounter = array();
	for($i = 0; $i < $intGroupCounter; $i++){
		$arrTmp = explode(",", $_data["ChoiceTNo".($i + 1)]);
		foreach($arrTmp as $strN){
			$arrN = explode(":", $strN);
			$intN = (int)$arrN[0];
			$arrCTNo[$intN] = $i;

			$arrNum[$intN] = sprintf("%02s", $intN);
			$arrOID[$intN] = (int)$arrN[1];
		}
	}
	foreach($arrCTNo as $intN => $intCNo){
		$arrChoiceTNo[$intCNo][] = sprintf("%02s", $intN);
	}
	for($i = 0; $i < $intGroupCounter; $i++){
		if(!is_array($arrChoiceTNo[$i])){
			$Err_Message = $_str10M15Wager["Err_Message"];
			$Err_HiddenMessage = $_str10M15Wager["Err_Message"];
			include("wager_error.php");

		}elseif(sizeof($arrChoiceTNo[$i]) > 12){
			$Err_Message 		= $_str10M15Wager["Err_Message"];
			$Err_HiddenMessage 	= $_str10M15Wager["Err_Message"];
			include("wager_error.php");
		}
		$arrChoiceList[$i] = '[<font class="left_jn_pg_choice_no">'.implode(",", $arrChoiceTNo[$i]). '</font>]';
		$arrOrderList[$i] = implode(",", $arrChoiceTNo[$i]);
		$arrChoiceCounter[$i] = sizeof($arrChoiceTNo[$i]);
	}
	$strOrderStakeNumber = implode("|", $arrOrderList);
	$strChoiceCounter = implode(" x ", $arrChoiceCounter);
	//取得下注總組數
	$intChoiceGroup = count(combinationForLine($arrChoiceTNo, $intGroupCounter));
}

//取得號碼的賠率
$arrGameDate = getMultiWagerArrayData($intLID, $intLType, $intGID, $intBT, $arrNum, $arrOID);
if($arrGameDate["isError"]){
	$Err_Message = $_str10M15Wager[$arrGameDate["Err_Message"]];
	include("wager_error.php");
}
$arrOdds = array();
$arrOddsID = array();
$flMaxOdds = 1;
foreach($arrGameDate["NData"] as $intN => $arrN){
	$arrOdds[$intN] = $arrN["Odds"];
	if($flMaxOdds < $arrN["Odds"])$flMaxOdds = $arrN["Odds"];
	$arrOddsID[] = $intN.":".$arrN["OddsID"];
}
$strWagerConditions = getWagerConditions($intLType, $intBT, $intNumber, null, $arrGameDate["GData"]["SerialNo"], null, $arrOrderList, $intChoiceGroup, $arrOdds);
$strWagerConditions = WagerFormTrans($intLID, $intBT, $strWagerConditions);

$strSpecialLimit = "";
$arrOtherMessage = array();
//當會員單場限額，大於此樂透單場限額
$chkEventLimit = $objMemberInfo -> arrEventLimit[$intLID][$intBT];
$arrOtherMessage = array();
$_arrLottoLimit[$arrGameDate["Bet_Type"]][0] = floor($_arrLottoLimit[$intBT][0] / $flMemERate);
if($chkEventLimit > $_arrLottoLimit[$intBT][0]){
	$chkEventLimit = $_arrLottoLimit[$intBT][0];
	$arrOtherMessage[0] = '<tr class="left_jn_pg_sp_limit_con"><td class="left_jn_pg_sp_limit_tip">'. $_str10M15Wager["MaxRoundLimitTitle"] .'</td><td class="left_jn_pg_sp_limit_value">'. $chkEventLimit .'</td></tr>';;

	$strSpecialLimit .= '<tr class="left_jn_pg_sp_limit_con"><td class="left_jn_pg_sp_limit_tip">'. $_str10M15Wager["MinWagerStakeTitle"] .'</td><td class="left_jn_pg_sp_limit_value">'. $chkBetLimit .'</td></tr>';
}
//當會員單注限額，大於此樂透單注限額
$chkBetLimit = $objMemberInfo -> arrBetLimit[$intLID][$intBT];
$_arrLottoLimit[$intBT][1] = floor($_arrLottoLimit[$intBT][1] / $flMemERate);
if($chkBetLimit > $_arrLottoLimit[$intBT][1]){
	$chkBetLimit = $_arrLottoLimit[$intBT][1];

	$arrOtherMessage[1] = '<tr class="left_jn_pg_sp_limit_con"><td class="left_jn_pg_sp_limit_tip">'. $_str10M15Wager["MinWagerStakeTitle"] .'</td><td class="left_jn_pg_sp_limit_value">'. $chkBetLimit .'</td></tr>';
}
//當會員單注限額，大於公司預收單注限額
$CompBetLimit = floor($_arrBetParam[$intBT][$intAN]["Com_BetLimit"] / ($objMemberInfo -> Layer6Scale*$flMemERate));
if($chkBetLimit > $CompBetLimit){
	$chkBetLimit = $CompBetLimit;
	$arrOtherMessage[1] = '<tr class="left_jn_pg_sp_limit_con"><td class="left_jn_pg_sp_limit_tip">'. $_str10M15Wager["MinWagerStakeTitle"] .'</td><td class="left_jn_pg_sp_limit_value">'. $chkBetLimit .'</td></tr>';
}
if(sizeof($arrOtherMessage) > 0)$strSpecialLimit = '  <tr class="left_jn_pg_sp_limit_title"><td colspan="2" class="left_jn_pg_sp_limit_title">'. $_str10M15Wager["SpecialLimitTitle"] .'</td></tr>'.implode("\n", $arrOtherMessage);;

//剩餘信用額度
$intCreditSurplus = $objMemberInfo -> CreditLine - (int)$_arrMemStake["_SUM"];

//取得最高派彩及未超過派彩的最高下注金額
$MaxPayOff = $_arrBetParam[$intBT][$intAN]["MaxPayOff"];
$MaxStakePayOff = floor($MaxPayOff / $flMaxOdds);


//取得 group money ... 剩餘信用額度 / 組數 ....再跟(會員,公司,系統,派彩的最高下注金額)比取最低
$intChoiceGroupMoney = floor($intCreditSurplus / $intChoiceGroup);
//print "min($chkBetLimit , $intChoiceGroupMoney , $MaxStakePayOff)";
$intChoiceGroupMoney = min($chkBetLimit , $intChoiceGroupMoney , $MaxStakePayOff);
$intMinChoiceGroupMoney = $_arrBetParam[$intBT][$intAN]["MinStake"];

//產生 CheckKeyValue
$arrCheckKey = explode(" ",microtime());
$CheckKeyValue1 = $arrCheckKey[0];
$CheckKeyValue2 = $arrCheckKey[1];

$fp = @file(__Membertemplate_Path."/10m15_wager.html");
$fp = implode("", $fp);
$fp = setHTMLCharset($fp);

while(list($k, $v) = each($_str10M15Wager)){
	$fp = str_replace("{".$k."}", $v, $fp);
}
$fp = str_replace("{ChoiceGroupMoney}", $intChoiceGroupMoney, $fp);
$fp = str_replace("{ChoiceGroup}", $intChoiceGroup, $fp);
$fp = str_replace("{ChoiceCounter}", $strChoiceCounter, $fp);
$fp = str_replace("{MinChoiceGroupMoney}", $intMinChoiceGroupMoney, $fp);

$fp = str_replace("{Account}", $objMemberInfo -> Account, $fp);
$fp = str_replace("{Currency}", $_ECRate[$objMemberInfo -> ERID][$_intLang], $fp);
$fp = str_replace("{CreditLine}", $objMemberInfo -> CreditLine, $fp);
$fp = str_replace("{CreditAlreadyUse}", $_arrMemStake["_SUM"], $fp);
$fp = str_replace("{CreditSurplus}", $intCreditSurplus, $fp);
$fp = str_replace("{MaxStakeMoney}", $intChoiceGroupMoney, $fp);
$fp = str_replace("{MinStakeMoney}", $_arrBetParam[$intBT][$intAN][MinStake], $fp);
$fp = str_replace("{MaxStakePayOff}", $MaxStakePayOff, $fp);
$fp = str_replace("{JoinMixBet}", $chkBetLimit, $fp);

$fp = str_replace("{MinWagerStake}", $objMemberInfo -> arrBetLimit[$intLID][$intBT], $fp);
$fp = str_replace("{MaxRoundLimit}", $objMemberInfo -> arrEventLimit[$intLID][$intBT], $fp);
$fp = str_replace("{SpecialLimit}", $strSpecialLimit, $fp);
$fp = str_replace("{ChoiceNumberList}", $strWagerConditions, $fp);
$fp = str_replace("{Periods}", $arrGameDate["GData"]["SerialNo"], $fp);
$fp = str_replace("{MaxPayOff}", $MaxPayOff, $fp);

$fp = str_replace("{OrderGambleID}", $intGID, $fp);
$fp = str_replace("{Bet_Type}", $intBT, $fp);
$fp = str_replace("{Number}", $intNumber, $fp);
$fp = str_replace("{OrderOddsID}", implode(",", $arrOddsID), $fp);
$fp = str_replace("{OrderOdds}", implode(",", $arrOdds), $fp);
$fp = str_replace("{OrderStakeNumber}", $strOrderStakeNumber, $fp);
$fp = str_replace("{LottoID}", $intLID, $fp);
$fp = str_replace("{UserID}", $objMemberInfo -> ID, $fp);
$fp = str_replace("{CheckKeyValue1}", $CheckKeyValue1, $fp);
$fp = str_replace("{CheckKeyValue2}", $CheckKeyValue2, $fp);
$fp = str_replace("{sid}", $_data[sid], $fp);

//輸出
WebOutputHTML($fp, 1);
?>